package com.xiaoshuidi.cloud.module.bpm.enums.reserveticket;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.framework.common.exception.ErrorCode;
import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 预约工单 - 状态枚举
 */
@AllArgsConstructor
@Getter
public enum ReserveStatusEnum {

    TO_BE_ASSIGNED("待分配","1"),
    FOLLOW_UP("跟进中","2"),
    COMPLETED("已完成","3");

    private String name;
    private String value;

    public static String getNameByValue(String value) {
        ReserveStatusEnum reserveStatusEnum = Arrays.stream(ReserveStatusEnum.values()).filter(p -> p.getValue().equals(value)).findFirst().orElse(null);
        if(ObjectUtil.isEmpty(reserveStatusEnum)){
            throw new ServiceException(new ErrorCode(100322, StrUtil.format("预约工单状态枚举value{}不存在",value)));
        }
        return reserveStatusEnum.getName();    }
}
